using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for AdminFormControl.
	/// </summary>
	public class AdminFormControl : System.Windows.Forms.UserControl
	{
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Label descriptionValueLabel;
    private System.Windows.Forms.Label descriptionLabel;
    private System.Windows.Forms.TextBox groupValueLabel;
    private System.Windows.Forms.Label groupLabel;
    private FreeFlowAdministrator.FormControl formControl;
    private FreeFlowAdministrator.UIActionsControl uiActionsControl;
    private System.Windows.Forms.Splitter splitter1;
    private System.Windows.Forms.Panel panel2;
    private FreeFlowAdministrator.FieldUsageControl fieldUsageControl;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Panel panel3;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AdminFormControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

      UIActionList actionList = new UIActionList();
      actionList.Add("Apply changes", "Apply any changes made", new ActionExecuteDelegate(ApplyChanges));
      uiActionsControl.Actions = actionList;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.formControl = new FreeFlowAdministrator.FormControl();
      this.panel1 = new System.Windows.Forms.Panel();
      this.descriptionValueLabel = new System.Windows.Forms.Label();
      this.descriptionLabel = new System.Windows.Forms.Label();
      this.groupValueLabel = new System.Windows.Forms.TextBox();
      this.groupLabel = new System.Windows.Forms.Label();
      this.uiActionsControl = new FreeFlowAdministrator.UIActionsControl();
      this.splitter1 = new System.Windows.Forms.Splitter();
      this.panel2 = new System.Windows.Forms.Panel();
      this.label1 = new System.Windows.Forms.Label();
      this.fieldUsageControl = new FreeFlowAdministrator.FieldUsageControl();
      this.panel3 = new System.Windows.Forms.Panel();
      this.panel1.SuspendLayout();
      this.panel2.SuspendLayout();
      this.panel3.SuspendLayout();
      this.SuspendLayout();
      // 
      // formControl
      // 
      this.formControl.Dock = System.Windows.Forms.DockStyle.Fill;
      this.formControl.Location = new System.Drawing.Point(0, 56);
      this.formControl.Name = "formControl";
      this.formControl.Size = new System.Drawing.Size(634, 273);
      this.formControl.TabIndex = 0;
      // 
      // panel1
      // 
      this.panel1.Controls.Add(this.descriptionValueLabel);
      this.panel1.Controls.Add(this.descriptionLabel);
      this.panel1.Controls.Add(this.groupValueLabel);
      this.panel1.Controls.Add(this.groupLabel);
      this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
      this.panel1.Location = new System.Drawing.Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(634, 56);
      this.panel1.TabIndex = 1;
      // 
      // descriptionValueLabel
      // 
      this.descriptionValueLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.descriptionValueLabel.Location = new System.Drawing.Point(136, 32);
      this.descriptionValueLabel.Name = "descriptionValueLabel";
      this.descriptionValueLabel.Size = new System.Drawing.Size(488, 16);
      this.descriptionValueLabel.TabIndex = 44;
      this.descriptionValueLabel.Text = "descriptionValueLabel";
      // 
      // descriptionLabel
      // 
      this.descriptionLabel.Location = new System.Drawing.Point(8, 32);
      this.descriptionLabel.Name = "descriptionLabel";
      this.descriptionLabel.Size = new System.Drawing.Size(100, 16);
      this.descriptionLabel.TabIndex = 43;
      this.descriptionLabel.Text = "Description:";
      // 
      // groupValueLabel
      // 
      this.groupValueLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.groupValueLabel.Location = new System.Drawing.Point(136, 12);
      this.groupValueLabel.Name = "groupValueLabel";
      this.groupValueLabel.Size = new System.Drawing.Size(488, 20);
      this.groupValueLabel.TabIndex = 42;
      this.groupValueLabel.Text = "groupValueLabel";
      // 
      // groupLabel
      // 
      this.groupLabel.Location = new System.Drawing.Point(8, 12);
      this.groupLabel.Name = "groupLabel";
      this.groupLabel.Size = new System.Drawing.Size(100, 16);
      this.groupLabel.TabIndex = 41;
      this.groupLabel.Text = "Group:";
      // 
      // uiActionsControl
      // 
      this.uiActionsControl.Actions = null;
      this.uiActionsControl.Dock = System.Windows.Forms.DockStyle.Right;
      this.uiActionsControl.Location = new System.Drawing.Point(634, 0);
      this.uiActionsControl.Name = "uiActionsControl";
      this.uiActionsControl.Size = new System.Drawing.Size(150, 432);
      this.uiActionsControl.TabIndex = 2;
      // 
      // splitter1
      // 
      this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
      this.splitter1.Location = new System.Drawing.Point(0, 329);
      this.splitter1.Name = "splitter1";
      this.splitter1.Size = new System.Drawing.Size(634, 3);
      this.splitter1.TabIndex = 4;
      this.splitter1.TabStop = false;
      // 
      // panel2
      // 
      this.panel2.Controls.Add(this.fieldUsageControl);
      this.panel2.Controls.Add(this.panel3);
      this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
      this.panel2.Location = new System.Drawing.Point(0, 332);
      this.panel2.Name = "panel2";
      this.panel2.Size = new System.Drawing.Size(634, 100);
      this.panel2.TabIndex = 5;
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8, 0);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(100, 16);
      this.label1.TabIndex = 5;
      this.label1.Text = "Field Usage";
      // 
      // fieldUsageControl
      // 
      this.fieldUsageControl.Dock = System.Windows.Forms.DockStyle.Fill;
      this.fieldUsageControl.Location = new System.Drawing.Point(0, 16);
      this.fieldUsageControl.Name = "fieldUsageControl";
      this.fieldUsageControl.Size = new System.Drawing.Size(634, 84);
      this.fieldUsageControl.TabIndex = 4;
      // 
      // panel3
      // 
      this.panel3.Controls.Add(this.label1);
      this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
      this.panel3.Location = new System.Drawing.Point(0, 0);
      this.panel3.Name = "panel3";
      this.panel3.Size = new System.Drawing.Size(634, 16);
      this.panel3.TabIndex = 6;
      // 
      // AdminFormControl
      // 
      this.Controls.Add(this.formControl);
      this.Controls.Add(this.splitter1);
      this.Controls.Add(this.panel2);
      this.Controls.Add(this.panel1);
      this.Controls.Add(this.uiActionsControl);
      this.Name = "AdminFormControl";
      this.Size = new System.Drawing.Size(784, 432);
      this.panel1.ResumeLayout(false);
      this.panel2.ResumeLayout(false);
      this.panel3.ResumeLayout(false);
      this.ResumeLayout(false);

    }
		#endregion

    private Action action;
    public void LoadAction(Action action)
    {
      this.action = action;

      descriptionValueLabel.Text = action.Description;
      groupValueLabel.Text = action.Group;

      Map map = new Map(action.Server, action.MapName);
      formControl.LoadForm(new FreeFlow.Administration.Form(action.Server, map.ProcedureName, action.Form));

      fieldUsageControl.LoadFieldUsage(action.FieldUsage);
    }

    private string ApplyChanges()
    {
      action.Group = groupValueLabel.Text;
      action.ApplyChanges();
      return Constants.ChangesApplied;
    }
	}
}
